//Player.cpp
/*
Player class
Created by: Taryn Green & Chris Groce
Updated: 10/14/2013
*/

#include "Player.h"
#include <cmath>
using namespace std;

Player::Player()
{
	roomSize=7;
	forwardSpeed = 0;
//	ySpeed = 0;
	leftSpeed = 0; //left is negative, right is positive
	upSpeed = 0; // positive is up
	size = 0.5f;	//Temporary size 
	vertFacing = 0;
	horFacing = 0;
	xPos = 0;
	yPos = 0;
	zPos = 0;
}

Player::Player(float mRoomSize)
{
	roomSize= mRoomSize;
	forwardSpeed = 0;
//	ySpeed = 0;
	leftSpeed = 0;
	upSpeed = 0;
	size = 0.5f;	//Temporary size 
	vertFacing = 0;
	horFacing = 0;
	xPos = 0;
	yPos = 0;
	zPos = 0;
}

float Player::getXPos(){
	return xPos;
}

float Player::getYPos(){
	return yPos;
}

float Player::getZPos(){
	return zPos;
}

float Player::getForwardSpeed()
{
	return forwardSpeed;
}
float Player::getLeftSpeed()
{
	return leftSpeed;
}
float Player::getUpSpeed()
{
	return upSpeed;
}

float Player::getSize()
{
	return size;
}

int Player::getHorFacing()
{
	return horFacing;
}

int Player::getVertFacing()
{
	return vertFacing;
}

void Player::incrementForwardSpeed()
{
	forwardSpeed +=0.1;
}
void Player::decrementForwardSpeed()
{
	forwardSpeed -=0.1;
}

void Player::setXPos(float x){
	xPos=x;
}

void Player::setYPos(float y){
	yPos=y;
}

void Player::setZPos(float z){
	zPos=z;
}

void Player::incrementLeftSpeed()
{
	leftSpeed +=0.1;
}
void Player::decrementLeftSpeed()
{
	leftSpeed -=0.1;
}

void Player::incrementUpSpeed()
{
	upSpeed ++;
}
void Player::decrementUpSpeed()
{
	upSpeed --;
}

void Player::turnLeft()
{
	horFacing -= 10;
	horFacing = horFacing % 360;
}

void Player::turnRight()
{
	horFacing +=10;
	horFacing = horFacing % 360;
}
void Player::turnUp()
{
	vertFacing += 10;
	vertFacing = vertFacing % 360;
}

void Player::turnDown()
{
	vertFacing -=10;
	vertFacing = vertFacing % 360;
}


void Player::updatePositions()
{
	float tmpX = xPos+forwardSpeed*cos((float) horFacing * (float) 3.14159/(float)180) * cos((float) vertFacing * (float) 3.14159/ (float) 180) /*+leftSpeed*sin((float)horFacing*(float)3.14159/(float)180)*/;
	float tmpZ = zPos-forwardSpeed*sin((float) horFacing * (float) 3.14159/(float)180) * cos((float) vertFacing * (float) 3.14159 / (float) 180)/*-leftSpeed*cos((float)horFacing*(float)3.14159/(float)180)*/;	
	float tmpY = yPos+forwardSpeed*sin((float) vertFacing * (float) 3.14159/(float) 180);

	if(tmpX > roomSize/2 - size/2) {
		xPos= roomSize/2 - size/2;
	}
	else if(tmpX < 0-roomSize/2 + size/2) {
		xPos= 0-roomSize/2 + size/2;
	}
	else {
		xPos= tmpX;
	}
	if(tmpY > roomSize/2 - size/2) {
		yPos= roomSize/2 - size/2;
	}
	else if(tmpY < 0-roomSize/2 + size/2) {
		yPos= 0-roomSize/2 + size/2;
	}
	else {
		yPos= tmpY;
	}
	if(tmpZ > roomSize/2 - size/2) {
		zPos= roomSize/2 - size/2;
	}
	else if(tmpZ < 0-roomSize/2 + size/2) {
		zPos= 0-roomSize/2 + size/2;
	}
	else {
		zPos= tmpZ;
	}
}

void Player::resetSpeeds()
{
	forwardSpeed = 0;
	leftSpeed = 0;
	upSpeed = 0;
}
